package com.tanhua.server.controller;

import com.tanhua.server.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Map;

@RestController
@RequestMapping("/user")
public class LoginConlroller {

    @Autowired
    private UserService userService;

    /**
     * 获取登录验证码
     * @param map
     * @return
     */
    @PostMapping("/login")
    public ResponseEntity login(@RequestBody Map map) {
        //获取参数
        String phone = (String) map.get("phone");
        //调用service方法
        userService.SendMsg(phone);
        //返回200状态码
        return ResponseEntity.ok(null);
    }

    /**
     * 登录校验验证码
     * @param map
     * @return
     */
    @PostMapping("/loginVerification")
    public ResponseEntity loginVerification(@RequestBody Map map) {
        //1，获取传递过来的参数
        String phone = (String) map.get("phone");
        String code = (String) map.get("verificationCode");
        //2，调用service进行登录校验
        Map retMap = userService.loginVerification(phone, code);
        //3，构造返回数据
        return ResponseEntity.ok(retMap);
    }
}
